<%--
  Created by IntelliJ IDEA.
  User: yang
  Date: 7/20/20
  Time: 19:51
  To change this template use File | Settings | File Templates.
--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>主页 </title>
    <script src=${theProjectName}/js/jquery.min.js></script>
    <!-- 导入 jquery    -->
    <link rel="stylesheet" href="${theProjectName}/css/home.css">
    <script src="${theProjectName}/js/addOne.js"></script>
    <%--   判断 addOne 是否为空  --%>
    <script src="${theProjectName}/js/delOne.js"></script>
    <%--   判断 删除框 是否为空  --%>
    <script>
        $(function () {
           // TODO 页面加载完毕
            setInterval(getLoginNumber,1000);
        });
        function getLoginNumber() {
            // TODO 获取当前登陆人数
            let xgr = new XMLHttpRequest()
            // 设置请求方式 地址
            xgr.open("POST", "${theProjectName}" + "/ajax/getLoginNumber");
            // post 设置请求头 Context-Type 模拟表单提交
            xgr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            // 设置参数
            xgr.send();
            xgr.onreadystatechange = function () {
                // TODO 判断响应的状态
                if (xgr.readyState === 4 && xgr.status === 200) {
                    // 赋值
                    console.log(xgr.responseText);
                    $("#loginNumber").html("当前登陆人数 ："+xgr.responseText);
                }
            }
        }
    </script>
</head>
<body>
<c:if test="${user != true}">
    <%--  没有登陆，转发到登陆页面   --%>
    <c:redirect url="/jsp/login.jsp"/>
</c:if>

<div style="height: 150px">
    <p id="loginNumber">当前登陆人数 1</p>
    <h2 align="left"> 用户 ${userName} 你好！
    </h2>
    <h2 align="right"><a href="${theProjectName}/logOut">登出</a></h2>
</div>
<div style="height: 100px">
    <h2><a href="${theProjectName}/getAll">获取所有</a></h2>
</div>
<div style="height: 400px">
    <h2>增</h2>
    <form action="${theProjectName}/addOne" method="post" id="addOne">
        <table>
            <tr>
                <td>学生 id</td>
                <td><input type="number" name="sid"></td>
            </tr>
            <tr>
                <td>学生姓名</td>
                <td><input type="text" name="sname"></td>
            </tr>
            <tr>
                <td>学生性别</td>
                <td>
                    男<input type="radio" value="m" name="sex" checked/>
                    &nbsp;
                    女<input type="radio" value="w" name="sex"/>
                </td>
            </tr>
            <tr>
                <td>学生年龄</td>
                <td><input type="number" name="sage"></td>
            </tr>

            <tr>
                <td>学生老师 ID</td>
                <td><input type="number" name="scid"></td>
            </tr>

            </tr>
            <tr>
                <td colspan="2">
                    <input type="reset" value="重置">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="submit" value="提交">
                </td>
            </tr>
        </table>

    </form>
</div>

<div style="height: 150px">
    <h2>删</h2>
    <h2>
        <form action="${theProjectName}/delOne" method="post" id="delOne">
            学生ID <input type="number" name="sid"> &nbsp;
            <input type="submit" value="提交">
        </form>
    </h2>


</div>
<div style="height: 400px">
    <h2>改</h2>
    <form action="${theProjectName}/changeOne" method="post">
        <table>
            <tr>
                <td>学生 id</td>
                <td><input type="number" name="sid"></td>
            </tr>
            <tr>
                <td>学生姓名</td>
                <td><input type="text" name="sname"></td>
            </tr>
            <tr>
                <td>学生性别</td>
                <td>
                    男<input type="radio" value="m" name="sex" checked/>
                    &nbsp;
                    女<input type="radio" value="w" name="sex"/>
                </td>
            </tr>
            <tr>
                <td>学生年龄</td>
                <td><input type="number" name="sage"></td>
            </tr>

            <tr>
                <td>学生老师 ID</td>
                <td><input type="number" name="scid"></td>
            </tr>

            </tr>
            <tr>
                <td colspan="2">
                    <input type="reset" value="重置">
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="submit" value="提交">
                </td>
            </tr>
        </table>

    </form>
</div>


<div style="height: 150px">
    <h2>查</h2>
    <h2>
        <form action="${theProjectName}/getOne" method="post">
            学生ID <input type="number" name="sid"> &nbsp;
            <input type="submit" value="提交">
        </form>
    </h2>
</div>


</body>
</html>
